package com.rykj.energy.common.utils;

import com.rykj.energy.common.enums.ResponseEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@ApiModel(description = "返回结果")
public class Result<T> {
    @ApiModelProperty("是否成功: true or false")
    private boolean success;

    @ApiModelProperty("描述性原因")
    private String message;

    @ApiModelProperty("错误码信息")
    private Integer code;

    @ApiModelProperty("业务数据")
    private T data;

    public Result(T data) {
        this(true, 0,null, data);
    }

    public Result(boolean success, Integer code, String message) {
        this(success, code,message, null);
    }

    public Result(boolean success, Integer code, String message, T data) {
        this.success = success;
        this.message = message;
        this.data = data;
        this.code = code;
    }

    public Result() {

    }

    public Result(ResponseEnum responseEnum) {
        this.code = responseEnum.getCode();
        this.message = responseEnum.getMessage();
    }

    public Result(ResponseEnum responseEnum, String message) {
        this.code = responseEnum.getCode();
        this.message = message;
    }

    public void setResult(ResponseEnum responseEnum) {
        this.code = responseEnum.getCode();
        this.message = responseEnum.getMessage();
    }

    public static <T> Result success(Integer code ,T data) {
//        return new ResponseResult(true, code,"SUCCESS", data);
        return new Result(true, code,"操作成功", data);
    }

    public static <T> Result success(T data) {
        return new Result(true, 0,"操作成功", data);
    }

    public static <T> Result success(String message, T data) {
        return new Result(true,0, message, data);
    }

    public static Result failure(String message) {
        return failure(-1, message);
    }

    public static Result failure(Integer code) {
        return new Result(false, code,"FAILURE", null);
    }

    public static Result failure(Integer code,String message) {
        return new Result(false,code, message, null);
    }





}
